package com.dut.bbs.activity;

import com.dut.bbs.R;
import com.dut.bbs.util.Settings;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;

public class SettingActivity extends PreferenceActivity implements
		OnPreferenceChangeListener {
	private SharedPreferences preferences;
	private CheckBoxPreference showPic,showIP,showSign,showPhone,autoUpdate;
	private EditTextPreference et_sign,et_quickReply;
	private ListPreference showBar,signColor;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.getPreferenceManager().setSharedPreferencesName("settings");
		addPreferencesFromResource(R.xml.preferences);	
		preferences = getPreferenceManager().getSharedPreferences();
		showPic = (CheckBoxPreference) getPreferenceScreen().findPreference("isPic");
		showIP = (CheckBoxPreference) getPreferenceScreen().findPreference("isIP");
		showSign = (CheckBoxPreference) getPreferenceScreen().findPreference("isBackWord");
		showPhone = (CheckBoxPreference) getPreferenceScreen().findPreference("isPhoneType");
		autoUpdate = (CheckBoxPreference) getPreferenceScreen().findPreference("isAuto");
		et_sign = (EditTextPreference) getPreferenceScreen().findPreference("backWords");
		et_quickReply = (EditTextPreference) getPreferenceScreen().findPreference("fastRe");
		showBar = (ListPreference) getPreferenceScreen().findPreference("barStat");
		signColor = (ListPreference) getPreferenceScreen().findPreference("signColor");
		showPic.setOnPreferenceChangeListener(this);
		showIP.setOnPreferenceChangeListener(this);
		showSign.setOnPreferenceChangeListener(this);
		autoUpdate.setOnPreferenceChangeListener(this);
		et_sign.setOnPreferenceChangeListener(this);
		et_quickReply.setOnPreferenceChangeListener(this);
		showBar.setOnPreferenceChangeListener(this);
		signColor.setOnPreferenceChangeListener(this);
		showPhone.setOnPreferenceChangeListener(this);
	}
	
	@Override
	public boolean onPreferenceChange(Preference arg0, Object value) {
		// TODO Auto-generated method stub
		String key = arg0.getKey();
		if("isPic".equals(key)){
			Settings.showPic=(Boolean)value;
		}else if("isIP".equals(key)){
			Settings.showIP=(Boolean)value;
		}else if("isBackWord".equals(key)){
			Settings.showSign=(Boolean)value;
		}else if("isPhoneType".equals(key)){
			Settings.showPhone=(Boolean)value;
		}else if("isAuto".equals(key)){
			Settings.auto_update=(Boolean)value;
		}else if("backWords".equals(key)){
			Settings.sign = (String)value;
		}else if("fastRe".equals(key)){
			Settings.quickReply = (String)value;
		}else if("barStat".equals(key)){
			Settings.showBar = (String)value;
		}else if("signColor".equals(key)){
			Settings.signColor = (String)value;
		}
		return true;
	}
	
}
